<?php
declare(strict_types=1);
/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://gitee.com/xmo/MineAdmin
 */

namespace Plugin\Organization\Http\Controller\Api;

use App\Http\Admin\Controller\AbstractController as AdminAbstractController;
use App\Http\Common\Middleware\AccessTokenMiddleware;
use App\Http\Common\Result;
use App\Http\CurrentUser;
use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\HttpServer\Request;
use Hyperf\Swagger\Annotation\Get;
use Hyperf\Swagger\Annotation\HyperfServer;
use Hyperf\Swagger\Annotation\JsonContent;
use Hyperf\Swagger\Annotation\Post;
use Hyperf\Swagger\Annotation\RequestBody;
use Mine\Swagger\Attributes\PageResponse;
use Plugin\Organization\Http\Request\Admin\RdOrganizeUserApplyRequest;
use Plugin\Organization\Schema\RdOrganizeUserApplySchema;
use Plugin\Organization\Service\RdOrganizeUserApplyService;

/**
 * 用户权限申请控制器
 * Class RdOrganizeUserApplyApiController
 */
#[HyperfServer(name: 'http')]
#[Middleware(middleware: AccessTokenMiddleware::class, priority: 100)]
final class RdOrganizeUserApplyApiController extends AdminAbstractController
{

     /**
     * 业务处理服务
     * RdOrganizeUserApplyService
     */
    public function __construct(
        protected readonly RdOrganizeUserApplyService $service,
        protected readonly CurrentUser $currentUser
    ) {}

    #[Get(
        path: '/organization/rdOrganizeUserApply/api/list',
        summary: '用户权限申请控制器列表',
        security: [['Bearer' => [], 'ApiKey' => []]],
        tags: ['用户权限申请控制器'],
    )]
    #[PageResponse(instance: RdOrganizeUserApplySchema::class)]
    public function page(Request $request): Result
    {
        return $this->success(data: $this->service->page(array_merge($request->all(), [
        'user_id' => $this->currentUser->id(),
        ]), (int) $request->query('page'), (int) $request->query('page_size')));
    }


    #[Post(
        path: '/organization/rdOrganizeUserApply/api',
        summary: '创建用户权限申请控制器',
        security: [['Bearer' => [], 'ApiKey' => []]],
        tags: ['用户权限申请控制器'],
    )]
    #[RequestBody(
        content: new JsonContent(ref: RdOrganizeUserApplyRequest::class, title: '创建用户权限申请控制器')
    )]
    #[PageResponse(instance: new Result())]
    public function create(RdOrganizeUserApplyRequest $request): Result
    {
        $this->service->create(array_merge($request->post(), [
            'user_id' => $this->currentUser->id()
        ]));
        return $this->success();
    }

    #[Get(
        path: '/organization/rdOrganizeUserApply/api/detail',
        summary: '用户权限申请控制器详情',
        security: [['Bearer' => [], 'ApiKey' => []]],
        tags: ['用户权限申请控制器'],
    )]
    #[PageResponse(instance: RdOrganizeUserApplySchema::class)]
    public function detail(): Result
    {
        return $this->success(data: $this->service->detail($this->currentUser->id()));
    }
}